<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta charset="utf-8"/>
    <title>用户登录</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/assets/libs/layui/css/layui.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/assets/css/login.css" media="all">
    <script>
        if (window != top)
            top.location.replace(location.href);
    </script>
</head>

<body>
<div class="login-wrapper">

    <div class="login-header">
        <img src="${pageContext.request.contextPath}/assets/images/logo.png">访客管理系统
    </div>

    <div class=" login-body">
        <div class="layui-card">
            <div class="layui-card-header">
                <i class="layui-icon layui-icon-engine"></i>&nbsp;&nbsp;管理员登录
            </div>
            <form class="layui-card-body layui-form layui-form-pane">
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-username"></i></label>
                    <div class="layui-input-block">
                        <input name="account" type="text" lay-verify="required" placeholder="账号" value=""
                               class="layui-input" autocomplete="off">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-password"></i></label>

                    <div class="layui-input-block">
                        <input name="passwd" type="password" lay-verify="required" placeholder="密码" value=""
                               class="layui-input" autocomplete="off">
                    </div>
                </div>
                <input type="hidden" name="role" value="admin" title="管理员">
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-auz"></i></label>
                    <div class="layui-input-block">
                        <input type="radio" name="role" value="admin" title="管理员" checked="">
                        <input type="radio" name="role" value="user" title="用户" checked="">
                    </div>
                </div>
                <div class="layui-form-item">
                    <button lay-filter="login-submit" class="layui-btn layui-btn-fluid" lay-submit>登 录</button>
                </div>
            </form>
        </div>
    </div>

    <div class="login-footer">
        <p>© 2021 访客管理系统 技术支持：源码空间站</p>
    </div>
</div>

<script type="text/javascript" src="${pageContext.request.contextPath}/assets/libs/layui/layui.js"></script>
<script>
    layui.config({
        base: 'module/'
    }).use(['form'], function () {
        var $ = layui.jquery;
        var form = layui.form;

        // 表单提交
        form.on('submit(login-submit)', function (obj) {
            layer.load(2);
            $.post('${pageContext.request.contextPath}/doLogin', obj.field, function (data) {
                var result=eval(data);
                if (200 == result.status) {
                    layer.msg('登录成功', {icon: 1, time: 1500}, function () {
                        location.replace('${pageContext.request.contextPath}/'+result.data);
                    });
                } else {
                    layer.closeAll('loading');
                    layer.msg('登录失败,用户名或者密码错误', {icon: 5});
                }
            }, 'JSON');
            return false;
        });
    });
</script>
</body>
</html>